<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>问题详情</title>
    <script src="jquery.min.js"></script>

</head>
<body>
<div id="wenti">
问题：<input type="text" id="wen">
</div>

<div id="wentimiaoshu">
问题描述：<input type="text" id="miaoshu">
</div>

<div id="wangyouhuida">
网友回答：
    <ul id="huida">

    </ul>
</div>

<div id="wodedaan">
<form method="get" >
    我来回答：<input type="text" id="myanswer" name="ansContent">
    <input type="hidden" id="qid" name="qid">
    <input type="submit" id="tijiao" value="提交答案">
    <a href="questions-list.html">返回首页</a>
</form>
</div>

<script>
    $(function () {
    var id= location.search.substring(1);//问题id 对应pid
        var count=0;
         alert(id);
         $("#qid").val(id);
       //
        //获得该问题
        $.get("getQuestion",{id:id},function (data) {
           count=data.data.answerCount;
           alert(count+"count");
           if(data.code==0){
               $("#wen").val(data.data.title);
               $("#miaoshu").val(data.data.detailDesc);
           }else{
               $("#wen").val("无数据");
               $("#miaoshu").val("无数据");
           }
        });
        //获得该为题的回答
        $.get("getAnswers",{pid:id},function (data) {
           $.each(data.data,function (i,o) {
               $("#huida").append("<li><div>"+o.ansdate+"</div></li>");
               $("#huida").append("<li><div>"+o.anscontent+"</div></li>");
           });
        });
        $("#myanswer").blur(function () {
           if($(this).val()==null||$(this).val()==''){
               alert("必须填写您的答案");
               return;
           }

        });
        $("#tijiao").click(function () {
        var ans=    {qid:id,ansContent:$("#myanswer").val(),id:id,answerCount:count};
              JSON.stringify(ans);
            $.get("addanswer",ans,function (data) {
              if(data.code==0){
                  alert("提交成功");
                  window.location.href="answers.html?"+id;
            }
              return false;
            });
        });
    });
</script>

</body>
</html>